package com.macro.mall.search.component;

import com.macro.mall.search.service.EsProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 每日定时将数据库商品全量导入到 Elasticsearch 的任务
 */
@Component
public class EsProductImportScheduler {

	private static final Logger LOGGER = LoggerFactory.getLogger(EsProductImportScheduler.class);

	@Autowired
	private EsProductService esProductService;

	/**
	 * 每天凌晨 00:00 触发，全量导入
	 */
	@Scheduled(cron = "0 0 0 * * ?")
	public void importAllProductsToEs() {
		int count = esProductService.importAll();
		LOGGER.info("Scheduled importAll finished, indexed {} products into Elasticsearch", count);
	}
}


